package kr.hkit.powerjava.chapter14;

import java.awt.Component;
import java.awt.HeadlessException;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

class MyFrame1 extends JFrame{

	public MyFrame1() throws HeadlessException {
		setTitle("BoxLayoutTest");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		JPanel panel=new JPanel();
		
		panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
		makeButton(panel,"Button1");
		makeButton(panel,"Button2");
		makeButton(panel,"Button3");
		makeButton(panel,"Button4");
		makeButton(panel,"Button5");
		add(panel);
		pack();setVisible(true);
	}

	private void makeButton(JPanel panel, String text) {
			JButton button=new JButton(text);
			button.setAlignmentX(Component.CENTER_ALIGNMENT);
			panel.add(button);
	}
}

public class BoxTest {
	public static void main(String[] args) {
		MyFrame1 f= new MyFrame1();
	}
}
